﻿using Arch.Data;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.ServiceModel.DomainServices.Server;
using System;
using Microsoft.Practices.Unity;

namespace Arch.DomainServices
{
    public class RepositoryDomainService : DomainService
    {
        [Dependency]
        public virtual IRepository Repository { get; set; }

        protected override void Dispose(bool disposing)
        {
            if (Repository is IDisposable)
            {
                (Repository as IDisposable).Dispose();
            }

            base.Dispose(disposing);
        }

        protected override bool PersistChangeSet()
        {
            Repository.SaveChanges();
            return base.PersistChangeSet();
        }
    }
}
